package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HaPatient;
import com.ruoyi.system.service.IHaPatientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 患者管理Controller
 * 
 * @author 鲍小伟
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/system/patient")
public class HaPatientController extends BaseController
{
    @Autowired
    private IHaPatientService haPatientService;

    /**
     * 查询患者管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(HaPatient haPatient)
    {
        startPage();
        List<HaPatient> list = haPatientService.selectHaPatientList(haPatient);
        return getDataTable(list);
    }

    /**
     * 导出患者管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:patient:export')")
    @Log(title = "患者管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HaPatient haPatient)
    {
        List<HaPatient> list = haPatientService.selectHaPatientList(haPatient);
        ExcelUtil<HaPatient> util = new ExcelUtil<HaPatient>(HaPatient.class);
        util.exportExcel(response, list, "患者管理数据");
    }

    /**
     * 获取患者管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:patient:query')")
    @GetMapping(value = "/{uid}")
    public AjaxResult getInfo(@PathVariable("uid") Long uid)
    {
        return success(haPatientService.selectHaPatientByUid(uid));
    }

    /**
     * 新增患者管理
     */
    @PreAuthorize("@ss.hasPermi('system:patient:add')")
    @Log(title = "患者管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HaPatient haPatient)
    {
        return toAjax(haPatientService.insertHaPatient(haPatient));
    }

    /**
     * 修改患者管理
     */
    @PreAuthorize("@ss.hasPermi('system:patient:edit')")
    @Log(title = "患者管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HaPatient haPatient)
    {
        return toAjax(haPatientService.updateHaPatient(haPatient));
    }

    /**
     * 删除患者管理
     */
    @PreAuthorize("@ss.hasPermi('system:patient:remove')")
    @Log(title = "患者管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uids}")
    public AjaxResult remove(@PathVariable Long[] uids)
    {
        return toAjax(haPatientService.deleteHaPatientByUids(uids));
    }
}
